package com.meida.module.bus.provider.handler;

import com.meida.common.base.entity.EntityMap;
import com.meida.common.base.utils.FlymeUtils;
import com.meida.common.mybatis.interceptor.GetInterceptor;
import com.meida.common.mybatis.query.CriteriaQuery;
import com.meida.module.bus.client.entity.BusOrder;
import com.meida.module.bus.client.entity.BusOrderQuestion;
import com.meida.module.bus.client.enums.UserTypeEnum;
import com.meida.module.user.client.entity.AppUser;
import org.springframework.stereotype.Component;

/**
 * 后台订单追问详情
 */
@Component
public class BusOrderQuestionGetHandler implements GetInterceptor {


    @Override
    public void prepare(CriteriaQuery cq, EntityMap entityMap) {
        cq.select(BusOrderQuestion.class, "questionId", "orderId", "userId", "userType", "content", "createTime");
        cq.select(BusOrder.class, "orderNo");
        cq.select(AppUser.class, "userName");
        cq.createJoin(BusOrder.class);
        cq.createJoin(AppUser.class);
    }

    @Override
    public void complete(CriteriaQuery cq, EntityMap map) {
        String userType = map.get("userType");
        UserTypeEnum userTypeEnum = UserTypeEnum.getByValue(userType);
        map.put("userTypeText", "");
        if (FlymeUtils.isNotEmpty(userTypeEnum)) {
            map.put("userTypeText", userTypeEnum.getLabel());
        }
    }
}
